package extrace.ui.main;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationListener;

import extrace.loader.HistoryLoader;
import extrace.misc.model.TransHistory;
import extrace.ui.main.ui.LoginActivity;
import extrace.ui.main.ui.MapActivity;
import extrace.ui.main.ui.TrackSearchActivity;
import extrace.ui.main.ui.TrackServiceActivity;


public class MyFragment extends Fragment {
    public static String[] mName = { "我的位置", "设置"};
    String name;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
    }

    View view = null;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.my_fragment, container, false);
        return view;
    }

    @Override
    public void onResume() {

        TextView textView = (TextView) view.findViewById(R.id.user_name);
        name = ((ExTraceApplication) this.getActivity().getApplication()).getLoginUser().getName();
        textView.setText("卓越快递");


        ListView list = (ListView) view.findViewById(R.id.list_sort);
        ArrayAdapter adapter = new ArrayAdapter(getActivity(), R.layout.list_item, mName);
        list.setAdapter(adapter);
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                switch (position) {
                    case 0:
                        Intent intentt;
                        intentt = new Intent(getActivity().getApplicationContext(), MapActivity.class);
                        startActivity(intentt);
                        return;
                    case 1:

                        Intent intent = new Intent();
                        intent.setClass(view.getContext(), SettingsActivity.class);
                        startActivityForResult(intent, 0);
                        return;


                }
            }
        });


        super.onResume();
    }
}
